package demo.DataStrucAndAlgo.Easy_pritice;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/26-08-26-18:35
 * @Description：demo.DataStrucAndAlgo.Easy_pritice
 */
public class Num_min {
    public static void main(String[] args) {
        int[] nums = {-1,2,1,-4};
        StringBuilder builder = new StringBuilder();
        builder.append('a').append('c');
        System.out.println(builder.toString());
        System.out.println(threeSumClosest(nums,1));

    }
    public static int threeSumClosest(int[] nums, int target) {

        int min = 10000;
        Arrays.sort(nums);
        int L = 0, R = nums.length-1;
        int i = 0;
        for (i = 0; i < nums.length-1; i++) {
            if(i > 0 && nums[i] == nums[i-1]){
                continue;
            }
            L = i + 1;
            R = nums.length-1;

            while(L<R){
                int temp = nums[L] + nums[i] + nums[R] - target;

                if(temp == 0){
                    return 0;
                }else if(temp < 0){
                    L++;
                }else{
                    R--;
                }
                if(Math.abs(temp) < Math.abs(min)){
                    min = temp;
                }
            }
        }
        return min;
    }
}
